package com.ant.storage.common;


import com.github.pagehelper.PageInfo;
import lombok.Data;

@Data
public class ResultPage <T>{
    /** 状态码 */
    private Integer code = 200;
    /** 提示信息 */
    private String msg;
    /**总条数*/
    private Integer count;
    /** 响应数据 */
    private T data;
    public ResultPage(){}
    private ResultPage(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }
    private ResultPage(String msg, T data,Integer count){
        this.count = count;
        this.msg = msg;
        this.data = data;
    }
    public static <T> ResultPage success(Integer code, String msg){
        return new ResultPage(code,msg);
    }

    public static <T> ResultPage success(String msg,T data,Integer count){
        return new ResultPage(msg,data,count);
    }

    public static ResultPage fail(ResultCode resultCode){
        return new ResultPage(resultCode.getResultCode(),resultCode.getResultMsg());
    }
    public ResultPage(PageInfo<T> page) {
        this.data = (T) page.getList();
        this.count = (int)page.getTotal();
    }

    public static <T> ResultPage success(String msg,PageInfo<T> page){
        ResultPage page1=new ResultPage();
        page1.code=200;
        page1.msg=msg;
        page1.count = (int)page.getTotal();
        page1.data = (T) page.getList();
        return  page1;
    }



}
